package com.qsl.ssyx.product.api;

import com.qsl.ssyx.model.product.Category;
import com.qsl.ssyx.model.product.SkuInfo;
import com.qsl.ssyx.product.service.CategoryService;
import com.qsl.ssyx.product.service.SkuInfoService;
import com.qsl.ssyx.vo.product.SkuInfoVo;
import com.qsl.ssyx.vo.product.SkuStockLockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "服务调用接口-product")
@RestController
@RequestMapping("/api/product")
public class ProductInnerController {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private SkuInfoService skuInfoService;

    @ApiOperation("根据分类Id获取分类信息-商品上下架接口")
    @GetMapping("getCategory/{categoryId}")
    public Category getCategory(@ApiParam(value = "分类Id", required = true) @PathVariable Long categoryId) {
        Category category = categoryService.getById(categoryId);
        return category;
    }

    @ApiOperation("根据skuId获取商品信息-商品上下架接口")
    @GetMapping("getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@ApiParam(value = "skuId", required = true) @PathVariable Long skuId) {
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo;
    }

    @ApiOperation("根据skuId获取商品信息列表")
    @GetMapping("getSkuInfoList/{skuId}")
    public List<SkuInfo> getSkuInfoList(@ApiParam(value = "skuId", required = true) @PathVariable Long skuId) {
        List<SkuInfo> skuInfo = skuInfoService.getSkuInfoListById(skuId);
        return skuInfo;
    }

    @ApiOperation("根据商品名称 查询SkuInfo集合")
    @GetMapping("getSkuInfosBySkuName/{skuName}")
    public List<SkuInfo> getSkuInfosBySkuName(@ApiParam(value = "skuName", required = true) @PathVariable String skuName) {
        List<SkuInfo> skuInfo = skuInfoService.getSkuInfosBySkuName(skuName);
        return skuInfo;
    }

    @ApiOperation("根据分类Ids获取分类信息集合")
    @GetMapping("getCategoryList/{categoryIds}")
    List<Category> getCategoryList(@ApiParam(value = "分类Id", required = true) @PathVariable List<Long> categoryIds) {
        List<Category> categoryList = categoryService.listByIds(categoryIds);
        return categoryList;
    }

    @ApiOperation("获取所有新人专享商品")
    @GetMapping("findNewPersionSkuInfoList")
    public List<SkuInfo> findNewPersionSkuInfoList() {
        List<SkuInfo> skuInfoList = skuInfoService.findNewPersionSkuInfoList();
        return skuInfoList;
    }

    @ApiOperation("获取所有商品分类")
    @GetMapping("findCategoryList")
    public List<Category> findCategoryList() {
        List<Category> categoryList = categoryService.list(null);
        return categoryList;
    }

    @ApiOperation("根据商品id获取商品信息") // 4表连接sku_info 和sku_image-sku图片 和attr-商品属性和 sku_poster-海报表
    @GetMapping("getSKuInfoVoBySkuId/{skuId}")
    public SkuInfoVo getSKuInfoVoBySkuId(@ApiParam(value = "商品Id", required = true) @PathVariable Long skuId) {
        SkuInfoVo skuInfoVo = skuInfoService.getSKuInfoVoBySkuId(skuId);
        return skuInfoVo;
    }

    @ApiOperation("公平锁锁定商品")
    @PostMapping("inner/checkAndLock/{orderNo}")
    public Boolean checkAndLock(@RequestBody List<SkuStockLockVo> skuStockLockVoList,
                                @ApiParam(value = "商品唯一Id", required = true) @PathVariable String orderNo) {
        Boolean flag = skuInfoService.checkAndLock(skuStockLockVoList, orderNo);
        return flag;
    }
}
